<?php
App::uses('AppModel', 'Model');
/**
 * Contact Model
 *
 * @property Note $Note
 * @property User $User
 * @property MailList $MailList
 */
class Contact extends AppModel {

/**
 * Validation rules
 *
 * @var array
 */
    public $virtualFields = array("full_name"=>"CONCAT(first_name, ' ' ,last_name)");
    public $displayField = 'full_name';
	public $validate = array(
        'email' => array(
            'email' => array(
                'rule' => array('email'),
            ),
            'unique_email'=> array(
                'rule'=> 'isUnique',
                'message'=> 'E-mail already in use. Please choose a different email address.',
            ),
        ),

//       'mobile' => array(
        //           'unique_number'=> array(
        //               'rule' => 'isUnique',
        //               'message' => 'This number is already in use. Please enter in a different number.'
        //           ),
//        ),

//        'home' => array(
//            'unique_number'=> array(
//                'rule' => 'isUnique',
//                'message' => 'This number is already in use. Please enter in a different number.'
//            ),
//        ),

//        'office' => array(
//            'unique_number'=> array(
//                'rule' => 'isUnique',
//                'message' => 'This number is already in use. Please enter in a different number.'
//            ),
//        ),

        'created_date' => array(
            'date' => array(
                'rule' => array('date'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),

        'modified_date' => array(
            'date' => array(
                'rule' => array('date'),
           /* ),
            'startEnd'=> array(
                'rule' => 'startDateGreaterEndDate',
                'message' => 'Modified date cannot be less than created date.'*/
            ),
        ),

        'dept_of_cont' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );

    //public function startDateGreaterEndDate(){
    //   return $this->data[$this->alias]['created_date'] < $this->data[$this->alias]['modified_date'];
    //}

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * hasMany associations
 *
 * @var array
 */
	public $hasMany = array(
		'Note' => array(
			'className' => 'Note',
			'foreignKey' => 'contact_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'contact_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);


/**
 * hasAndBelongsToMany associations
 *
 * @var array
 */
	public $hasAndBelongsToMany = array(
		'MailList' => array(
			'className' => 'MailList',
			'joinTable' => 'mail_lists_contacts',
			'foreignKey' => 'contact_id',
			'associationForeignKey' => 'mail_list_id',
			'unique' => 'keepExisting',
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => ''
		)
	);

}
